#!/bin/bash

#安装php-apache2
installPHPAndApache2() {
    sudo apt install -y apache2 php php-cgi php-cli php-common \
        php-curl php-dev php-fpm php-gd php-json \
        php-mbstring php-mysql php-odbc php-readline php-sqlite3 \
        php-xml php-xsl php-zip php-xdebug

    if [ ! -d /home/${user}/project/php ]; then
        mkdir -p /home/${user}/project/php
    fi
    #替换localhost的默认目录为：/home/${user}/project/php
    sudo sed -i "s#/var/www/html#/home/${user}/project/php#" /etc/apache2/sites-available/000-default.conf
    #/var/www/
    sudo sed -i "s#/var/www/#/home/${user}/project/php#" /etc/apache2/apache2.conf
    sudo cp /var/www/html/index.html /home/${user}/project/php
    sudo chown -R ${user}.${user} /home/${user}/project/php
    sudo setfacl -R -m user:www-data:rwx /home/${user}/project/php
    sudo systemctl start apache2
    sudo systemctl enable apache2
}

installPHPAndApache2